<!--
 * @Description: 
 * @Author: 47
 * @Date: 2023-01-05 15:07:47
 * @LastEditors: 47
 * @LastEditTime: 2023-01-17 17:31:50
-->
<template>
    <div class="answer-sheet">
        <div class="exam-msg">
        <!-- 题目信息 -->
            <div class="title" v-if="obj.code == 1">
                <div class="title-num">一、简答题</div>
                <div class="title-content">
                   {{ obj.homework_content}}
                    <!-- 1、请同学们从选题范围中任选—种形式，按照要求完成期末作业;<br>
                    2、每位同学均需要把作业上传到学习通“考试”模块，上传的文件以“班级+学号+姓名”命名，提交时间截止到2023年2月10日23:00;<br>
                    3、有任何疑惑的地方，请及时与代课教师联系。<br>
                    4、有任何疑惑的地方，请及时与代课教师联系。<br>
                    5、有任何疑惑的地方，请及时与代课教师联系。<br> -->
                </div>
            </div>

            <div class="title" v-if="obj.code == 2">
                <div class="title-num">一、简答题</div>
                <div class="title-content" v-html="obj.test_content"></div>
            </div>

            <!-- 答案 -->

            <div class="teditor1">
              <TEditor ref="editor" v-model="content"/>
            </div>

            <!-- <div class="answer">
                 <van-field v-model="value"  placeholder="请输入答案" />
                 <div class="other-icon">
                    <van-icon name="photo-o" />
                    <van-icon name="credit-pay" />
                    <van-icon name="link-o" />
                 </div>
            </div> -->
        </div>

        <!-- 提交 -->
        <div class="submit-btn">
            <van-button type="primary" @click=" dialogShow = true" :disabled="!content">提交</van-button>
        </div>
        <Dialog v-model:show="dialogShow" title="提示" message="确认是否提交?" show-cancel-button @confirm="confirm(obj.code,obj.homework_id,obj.test_id)" />
    </div>
</template>

<script setup>
import {Button, Dialog } from 'vant';
import 'vant/es/toast/style';
import 'vant/es/dialog/style';
// import { getCurrentInstance } from 'vue'
// 引入dayjs
import dayjs from 'dayjs'
import {ref} from "vue"
import {  defineProps } from 'vue'
// 引入仓库
import { useCourseStore } from '@/stores/course'
import { onMounted } from '@vue/runtime-core'
import { storeToRefs } from 'pinia'
// 引入路由
import {useRouter,useRoute} from 'vue-router'

const router = useRouter()
const route = useRoute()

//实例化仓库对象
const course = useCourseStore()
//解构方法
const { addContent } = course

// const { proxy } = getCurrentInstance();

const content = ref('')

const dialogShow = ref(false);

const confirm = async (judgeCode,homeworkId,testId) => {
    let submitTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm')
    await addContent({
        id:homeworkId ? homeworkId : testId,
        userId:1,
        content:content.value,
        judgeCode,
        submitTime
    })

    // console.log("提交成功");
    // 跳转到考试提交成功/作业提交成功页面 如果是考试页面要携带testId
    if (testId) {
        
        router.push({
            name:'examsuccess',
            params:{
                testId
            }
        })
    
    }else{
        router.push('/homeworksuccess')
    }

}


// const submit =  async (judgeCode,homeworkId,testId) => {
//         show.value = true
// }
const props = defineProps(['obj'])

</script>

<style scoped lang="less">
.answer-sheet{
    .exam-msg{
        padding-top: 45px;
        padding-bottom: 55px;
        .title{
            padding: 10px;
            .title-num{
                font-size: 15px;
                font-weight: 600;
            }
            .title-content{
                font-size: 14px;
                padding: 10px;
                line-height: 20px;
            }
        }
        .teditor1{
          width: 90%;
          height: 300px;
          margin: 0px 20px;
        }
        .answer{
            width: 90%;
            height: 300px;
            margin: 0px 20px;
            border: 1px solid;
            border-color: gainsboro;
            .van-field{
                width: 100%;
                height: 85%;
            }
            .other-icon{
                width: 100%;
                height: 40px;
                .van-icon{
                    font-size: 25px;
                    padding: 10px;
                    color: #898989;
                }
            }
        }

    }
    .van-button{
        width: 95%;
        position: fixed;
        bottom: 0;
        margin: 0 10px;
    }
}
</style>
